<?php

/**
 * @user magein
 * @date 2023/12/4 15:13
 */

namespace magein\sms;

/**
 * 平台设置信息
 */
class Setting
{

    /**
     * 使用的类
     * @var string
     */
    protected $class;

    /**
     * 账号可用列表
     * @var
     */
    protected $use;

    /**
     * 账号列表
     * @var array
     */
    protected $accounts = [];

    public function __construct($params)
    {
        $this->setClass($params['class'] ?? '');
        $this->setUse($params['use'] ?? []);
        $this->setAccounts($params['accounts'] ?? []);
    }

    /**
     * @return string
     */
    public function getClass(): string
    {
        return $this->class;
    }

    /**
     * @param string $class
     */
    public function setClass(string $class): void
    {
        $this->class = $class ?: '';
    }

    /**
     * @return array|mixed
     */
    public function getUse(): array
    {
        return $this->use ?: [];
    }

    /**
     * @param array|string $use
     */
    public function setUse($use): void
    {
        if (!is_array($use) && $use) {
            $use = [$use];
        }

        $this->use = $use ?: [];
    }

    public function getAccounts(): array
    {
        return $this->accounts ?: [];
    }

    /**
     * @param array|string $accounts
     * @return void
     */
    public function setAccounts($accounts): void
    {
        if (!is_array($accounts) && $accounts) {
            $accounts = [$accounts];
        }

        $this->accounts = $accounts ?: [];
    }
}